// XMLMgr.h: interface for the CXMLMgr class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_XMLMGR_H__6DD2D0F7_D24E_4099_A3BE_A8AEB254A2BE__INCLUDED_)
#define AFX_XMLMGR_H__6DD2D0F7_D24E_4099_A3BE_A8AEB254A2BE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#import "msxml.dll" raw_interfaces_only

using namespace MSXML;

class CXMLMgr
{
public:
	CXMLMgr();
	virtual ~CXMLMgr();

public:
	HRESULT 
		InsertChild(MSXML::IXMLDOMNode* /*pNewNode*/ , MSXML::IXMLDOMNode* /*pRefNode*/ , MSXML::IXMLDOMNode* /*pParentNode*/ = NULL );

	MSXML::IXMLDOMNode* 
		GetChild(const long /*lIndex*/ , MSXML::IXMLDOMNodeList* /*pList*/) const;

	CString 
		GetNodeName(MSXML::IXMLDOMNode* /*pNode*/);

	CString 
		GetText(MSXML::IXMLDOMNode* /*pElement*/);

	MSXML::IXMLDOMNode* 
		GetParent(MSXML::IXMLDOMElement* /*pElement*/) const;

	HRESULT 
		RemoveElement(MSXML::IXMLDOMElement* /*pElementToRemove*/ , MSXML::IXMLDOMNode* /*pParent*/);

	HRESULT 
		RemoveElement(MSXML::IXMLDOMElement* /*pElementToRemove*/);

	HRESULT 
		ReplaceElement(MSXML::IXMLDOMElement* /*pNewElement*/ , MSXML::IXMLDOMElement* /*pOldElement*/ , MSXML::IXMLDOMNode* /*pParent*/);

	HRESULT 
		CreateElement(CString /*lpcstrElementName*/, CString /*lpcstrElementText*/ , MSXML::IXMLDOMNode* /*pParentNode*/ , bool /*bAdd*/ = true , int /*nLevel*/ = 1);
	
	HRESULT 
		CreateComments(CString /*lpcstrComment*/);

	HRESULT 
		CreateXMLFileHeader();

	HRESULT 
		CreateRoot(CString /*lpcstrRootName*/ , CString /*lpcstrRootText*/ = NULL);

	MSXML::IXMLDOMElement* 
		GetRoot() const { return m_pXMLRoot; }

	MSXML::IXMLDOMNode * 
		GetFirstChild() const;
	
	MSXML::IXMLDOMNode * 
		GetFirstChild(MSXML::IXMLDOMNode* /*pNode*/) const;

	MSXML::IXMLDOMNode * 
		GetLastChild(MSXML::IXMLDOMNode* /*pNode*/) const;

	MSXML::IXMLDOMNode * 
		GetLastChild() const;

	MSXML::IXMLDOMNode * 
		GetNextSibling(MSXML::IXMLDOMNode* /*pNode*/) const;

	MSXML::IXMLDOMNodeList	* 
		GetChildList(MSXML::IXMLDOMNode* /*pNode*/) const;

	MSXML::IXMLDOMNode	* 
		GetItemNode(const long /*lIndex */, MSXML::IXMLDOMNodeList* /*pList*/) const;	

	const long 
		GetNoOfChilds(MSXML::IXMLDOMNodeList* /*pList*/) const;
	
	CString 
		GetItemText(MSXML::IXMLDOMNode* /*pNode*/);

	bool	
		Load(CString /*lpcstrXMLFileName*/);

	HRESULT 
		Save(CString /*lpcstrXMLFileName*/);
	
	HRESULT 
		Initlize() const;

	void	
		Release();

	MSXML::IXMLDOMElement*	
		GetLastItemAdded() const { return m_pLastItemAdded; }

	static int XMLMemoryHandler(size_t /* size */);

private:
	void 
		Release(MSXML::IXMLDOMDocument*	/*pXMLDoc*/);	
	void 
		Release(MSXML::IXMLDOMElement*		/*m_pXMLRoot*/);

	HRESULT 
		AppendChildToParent(MSXML::IXMLDOMNode* /*pChild*/, MSXML::IXMLDOMNode* /*pParent*/);

	void 
		AddWhiteSpaceToNode(MSXML::IXMLDOMDocument* /*pDOMDoc*/, BSTR /*bstrWs*/, MSXML::IXMLDOMNode* /*pNode*/);

	void 
		Destroy();

	void 
		SetIndentLevel(int /*nLevel*/ , MSXML::IXMLDOMNode* /*pParentNode*/);
	
	HRESULT 
		SetNodeText(CString /*lpcstrText*/ , MSXML::IXMLDOMElement* /*pNode*/);
	
	MSXML::IXMLDOMElement* 
		CreateNode(CString /*lpcstrRootName*/ , MSXML::IXMLDOMElement* /*pNode*/);

	CString 
		ReturnBuffer(BSTR /*bstr*/);

private:
	MSXML::IXMLDOMDocument*	m_pXMLDomDoc;		// NULL;
	MSXML::IXMLDOMElement*		m_pXMLRoot;			// NULL;
	MSXML::IXMLDOMElement*		m_pLastItemAdded;	// NULL;

	CString	m_Buffer;
	CString m_pBufLPCSTR;
	CString m_pBufStr;

	static CXMLMgr*		m_pThis;
};

#endif // !defined(AFX_XMLMGR_H__6DD2D0F7_D24E_4099_A3BE_A8AEB254A2BE__INCLUDED_)

